package com.aorise.service.system.impl;

import com.aorise.mapper.system.SysConfigMapper;
import com.aorise.model.system.*;
import com.aorise.service.system.SysConfigService;
import com.aorise.utils.ConstDefine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author:cat
 * @Desicription: 系统配置接口服务实现类
 * @Date:Created in 2019-05-28
 * @Modified By:
 */
@Service
public class SysConfigServiceImpl implements SysConfigService {

    @Autowired
    private SysConfigMapper sysConfigMapper;

    /**
     * @Author:cat
     * @Description 根据类别查询系统配置信息
     * @params: conType 类别
     * @Date:2019-05-28
     * @Return: List<SysConfigModel> 系统配置信息集合
     * @Modified By:
     */
    @Override
    public List<SysConfigModel> getSysConfig(Integer conType) {
        Map<String, Object> map = new HashMap<>();
        map.put("conType", conType);
        map.put("state", ConstDefine.STATE_ABLE);

        return sysConfigMapper.getSysConfig(map);
    }

    /**
     * @Author:cat
     * @Description 修改系统配置信息
     * @params: sysConfigEditVOList 系统配置信息集合
     * @Date:2019-05-28
     * @Return: Integer 影响行数
     * @Modified By:
     */
    @Override
    @Transactional
    public Integer updateSysConfig(List<SysConfigEditVO> sysConfigEditVOList) {
        int iRet = 0;
        if(sysConfigEditVOList.size()>0){
            for (int i = 0; i < sysConfigEditVOList.size(); i++) {
                sysConfigEditVOList.get(i).setState(ConstDefine.STATE_ABLE);
                iRet += sysConfigMapper.updateSysConfig(sysConfigEditVOList.get(i));

            }
        }

        return iRet;
    }

}
